/**
 * fileName:  EfficacyBean.java
 * author:  Lei
 * Company:  Cloudland Studio
 * Createdate:  2014-6-3 下午10:26:04
 *
 * All rights Reserved, Designed By cloudland Copyright(C) 2010-2011
 *   
 * Modification  History:
 *     Date           Author        Version        
 * -------------------------------------------
 * 2014-6-3          Lei            1.0        
 *
 * Why & What is modified:
 * 1.0: 文件创建
 */
package org.cloudland.commercial.masterdata.handler.support;

import org.cloudland.commercial.masterdata.bean.EfficacyInfo;
import org.cloudland.commercial.masterdata.exception.ExcepConst;
import org.cloudland.commercial.masterdata.exception.MasterDataException;
import org.cloudland.commercial.masterdata.store.entity.EfficacyEntity;
import org.cloudland.commercial.masterdata.store.entity.PageQueryEntity;
import org.cloudland.commercial.masterdata.store.read.EfficacyReader;
import org.cloudland.commercial.masterdata.store.write.EfficacyWriter;

 /**
 * <pre> 
 * 功效领域实体
 * </pre>
 * @ClassName  EfficacyBean
 * @author  Lei
 * @version  %I%, %G%
 * @see  
 * @since   JDK1.6
 *
 */
public class EfficacyBean implements EfficacyInfo {
	
	/**
	 * entity 功效领域对象
	 */
	private EfficacyEntity efficacyEntity;
	
	/**
	 * efficacyWriter 写数据库操作，用于新增、修改、删除数据库操作
	 */
	private EfficacyWriter efficacyWriter;
	
	/**
	 * efficacyReader 功效字典查询操作
	 */
	private EfficacyReader efficacyReader;

	/**
	 * <pre>
	 * TODO 请充分描述该构造函数的作用，及其参数的作用。
	 * </pre>
	 *
	 * @param efficacyWriter
	 * @param efficacyReader   
	 */
	public EfficacyBean(EfficacyWriter efficacyWriter, EfficacyReader efficacyReader) {
		this(new EfficacyEntity(), efficacyWriter, efficacyReader);
	}

	/**
	 * <pre>
	 * TODO 请充分描述该构造函数的作用，及其参数的作用。
	 * </pre>
	 *
	 * @param entity
	 * @param efficacyWriter
	 * @param efficacyReader   
	 */
	public EfficacyBean(EfficacyEntity entity, EfficacyWriter efficacyWriter, EfficacyReader efficacyReader) {
		this.efficacyEntity = entity;
		this.efficacyWriter = efficacyWriter;
		this.efficacyReader = efficacyReader;
	}

	/**
	 * @return
	 */
	public String getId() {
		return efficacyEntity.getId();
	}

	/**
	 * @return
	 */
	public String getName() {
		return efficacyEntity.getName();
	}

	/**
	 * @return
	 */
	public String getDesc() {
		return efficacyEntity.getDesc();
	}

	/**
	 * @return
	 */
	public Integer getSort() {
		return efficacyEntity.getSort();
	}

	/**
	 * @param name
	 */
	public void setName(String name) {
		efficacyEntity.setName(name);
	}

	/**
	 * @param desc
	 */
	public void setDesc(String desc) {
		efficacyEntity.setDesc(desc);
	}

	/**
	 * @param sort
	 */
	public void setSort(Integer sort) {
		efficacyEntity.setSort(sort);
	}

	/**
	 * 
	 */
	public void submit() {
		
		if (null != efficacyEntity.getId() && efficacyEntity.getId().length() > 0) {
			this.efficacyWriter.update(efficacyEntity);
		} else {
			PageQueryEntity<EfficacyEntity> result = this.efficacyReader.findEfficacyByName(efficacyEntity.getName(), 0, 9);
			if (result.count() > 0) {
				throw new MasterDataException(ExcepConst.EFFICACY_REPETITION_0001);
			}
			this.efficacyWriter.save(efficacyEntity);
		}
		
	}

}
